﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title></title>
    <link href="/Static/demo.css" rel="stylesheet" />
    <script src="/Static/boot.js"></script>
    <link href="/Static/miniui/themes/blue/skin.css" rel="stylesheet" />
    <style type="text/css">
        html, body {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <form id="form1" method="post">
        <fieldset style="border: solid 1px #aaa; padding: 3px;">
            <legend>基本信息</legend>
            <div style="padding-left: 11px; padding-bottom: 5px;">
                <table style=" font-size:12px">
                    <tr>
                        <td>
                            型号名称：
                        </td>
                        <td>
                            <input name="ModelName" class="mini-textbox" required="true" style="width: 200px;" />
                        </td>
                        <td align="left">
                            型号显示名称：
                        </td>
                        <td>
                            <input name="ModelDisplayName" class="mini-textbox" required="true" style="width: 200px;" />
                        </td>
                    </tr>
                    <tr>
                        <td align="left">
                            所属品牌：
                        </td>
                        <td>
                            <input name="BrandsID" class="mini-combobox" style="width:200px;" required="true" textfield="BrandsDisplayName" valuefield="ID" emptytext="请选择..."
                                   value="" allowinput="false" shownullitem="true" url="/Ajax/AjaxService.aspx?method=GetPartsBrandList&pageIndex=0" nullitemtext="请选择..." />
                        </td>
                        <td >
                            是否可用：
                        </td>
                        <td>
                            <input name="IsAvailable" class="mini-combobox" style="width:200px;" required="true" textfield="text" valuefield="id" emptytext="请选择..."
                                   value="" allowinput="false" shownullitem="true" url="/ConfigData/IsActive.txt" nullitemtext="请选择..." />
                        </td>
                    </tr>
                </table>
            </div>
        </fieldset>


        <div style="text-align: center; padding: 30px;">
            <a class="mini-button" onclick="onOk" style="width: 60px; margin-right: 20px;">确定</a>
            <a class="mini-button" onclick="onCancel" style="width: 60px;">取消</a>
        </div>
        <input id="hd_action" name="action" class="mini-textbox" style="display:none" />
        <input name="ID" class="mini-hidden" />
    </form>

    <script type="text/javascript">
        mini.parse();

        var form = new mini.Form("form1");
        /**保存数据*********************************************************************/
        function SaveData() {
            var o = form.getData();
            form.validate();
            if (form.isValid() == false) return;

            var json = mini.encode([o]);
            // alert(json);
            var strAction = mini.getbyName("action").getValue();

            $.ajax({
                url: "/Ajax/AjaxService.aspx?method=EditModel",
                data: { action: strAction, data: json, ID: mini.getbyName("ID").getValue() },
                cache: false,
                success: function (text) {
                    var result = $.parseJSON(text);

                    if (result.res != "操作成功") {
                        mini.alert("操作失败!" + result.error);
                    } else {
                        CloseWindow("save");
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }

        /**加载数据*********************************************************************/
        function SetData(data) {
            if (data.action == "Update") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);

                mini.getbyName("ID").setValue(data.ID);
                mini.getbyName("action").setValue(data.action);
                
                //查询基本信息
                $.ajax({
                    url: "/Ajax/AjaxService.aspx?method=GetPartsModelList&pageIndex=0&pageSize=10",
                    cache: false,
                    data: { id: data.ID },
                    success: function (text) {
                        //将字符串反序列化为JS对象
                        var o = mini.decode(text);
                        //注意此处返回的有data及total两组数据
                        //alert(o.data[0].ID);
                        form.setData(o.data[0]);
                        if (o.data[0].IsAvailable) {
                            mini.getbyName("IsAvailable").setValue("Y");
                        } else {
                            mini.getbyName("IsAvailable").setValue("N");
                        }
                        form.setChanged(false);

                        //记录页面模式
                        mini.getbyName("action").setValue(data.action);
                    }
                });
            }
            if (data.action == "Insert") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                mini.getbyName("action").setValue(data.action);
                mini.getbyName("IsAvailable").setValue("Y");

            }

        }
        /**获取表单中相关信息********************************************************************************/
        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }

        function onCloseClick(e) {
            var btnEdit = this;
            btnEdit.setValue("");
            btnEdit.setText("");
        }
    </script>
</body>
</html>
